package com.ycc;


import com.ycc.model.entity.User;
import io.jsonwebtoken.Claims;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import static com.ycc.utils.JwtUtil.*;

@SpringBootTest
public class testJwt {

    @Test
    public void testGenerateToken(){
        User user = new User();
        user.setId(2);
        user.setOpenid("oItwI7R8QMbEMakpREj5PHw8ke8");
        user.setUsername("凝雨");
        String token = generateToken(user);
        System.out.println(token);
    }

    @Test
    public void testParse(){
        String token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJvSXR3STdSOFFNYkVNYWtwUkVqNVBIdzhrZTgiLCJpYXQiOjE3MTY4OTYzNjcsImV4cCI6MTcxNjg5OTk2N30.NUnWkltqVLJS5dcN5VSRYVuRQzYj4PMp7oJLPZ0Kghg";
        Claims claims = parseToken(token);
        System.out.println(claims.getSubject());
    }

    @Test
    public void testisTokenExpired() {
        String token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJvdEl3STdSOFFNYkVNYWtwUkVqNVBIaHc4a2U4IiwiaWF0IjoxNzE2NzExNjg4LCJleHAiOjE3MTY3MTUyODh9.4CDWo4HwwiJAdY7DgVLMozca1YegTS57snf7786F1gk";
        boolean tokenExpired = isTokenExpired(token);
        System.out.println(tokenExpired);
    }
}
